<?php
/**
 * Joomla! 1.5 component jhtraq
 *
 * @version $Id: view.html.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 * Traq type system for Joomla
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
class JhtraqViewDefault extends JView {
    function display($tpl = null) {
//    $model =& JhtraqHelper::getModel('jhtraq');
//    print_r($model);

		$task = JRequest::getCmd('task', 'index');
		$tpl = $this->$task();
		
        parent::display($tpl);
    }
	
	function index()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->assignRef('projects', $model->countProjects());
		$this->assignRef('tickets', $model->countTickets());
		$this->assignRef('users', $model->countUsers());
		$this->version =  '1.0.0 Beta';
                $this->latest = $this->getVersion();

		
	}

    function getVersion($url="http://jhshop.info/jhproject/jhtraq/information?layout=latest"){
         $ch = curl_init();
         curl_setopt($ch,CURLOPT_URL, $url);
         curl_setopt($ch,CURLOPT_FRESH_CONNECT,TRUE);
	curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
         curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
         curl_setopt($ch,CURLOPT_REFERER,'JHTrack Admin Area');
         curl_setopt($ch,CURLOPT_TIMEOUT,10);
         $html=curl_exec($ch);
	  curl_close($ch);
         return $html;
    }

  function latestNews()
  {
    $url = 'http://feeds.feedburner.com/Jhtraq-JhShop-TheArtOfEcommerce';
    $data = $this->getVersion($url);
    if($data){
      $info = new SimpleXMLElement($data);
    }else{
      $info = new stdClass();
      $info->channel->item = array();
    }
    return $info;
  }

	

	
	
}
?>
